<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript演示</title>
</head>
<body>
<input type="button" onclick="on()" value="开灯">
<img id="light" src="../imgs/off.gif">
<input type="button" onclick="off()" value="关灯">
<script>
    //点击开关灯
    /*function on() {

       document.getElementById('light').src="../imgs/on.gif";

    }
    function off() {
        document.getElementById('light').src='../imgs/off.gif';
    }*/

    //自动开关灯
    var nub=0;
    setInterval(
        function eat () {


            if (nub%2==0){
                document.getElementById('light').src='../imgs/off.gif';
            }else {
                document.getElementById('light').src="../imgs/on.gif";
            }
            nub++;

        },1000);
</script>
</body>
</html>